<template>
	<!-- 列表部分 begin -->
	<view class="cu-card dynamic no-card margin-tb-sm" :style="index==0?'margin-top:0;border-top:1px solid #eee;':''">
		<view class="cu-item shadow">
			
			<!-- 头像部分 begin -->
			<view class="cu-list menu-avatar">
				<view class="cu-item">
					<view class="cu-avatar radius lg" :style="_item.goods.img?'background-image:url('+_item.goods.img+')':''"></view>
					<view class="content flex-sub">
						<view>
							{{_item.goods.name}}
						</view>
						<view class="text-gray text-sm flex justify-between">
							<view v-if="_item.goods.price==0" class="cu-tag radius sm light bg-green">
								免费
							</view>
							<text v-else class="text-red text-sm" style="display: inline-block;">
								<text class="text-xs">单价￥</text>{{_item.goods.sellPrice}}元
							</text>
						</view>
					</view>
					<view class="action text-red" style="width:150rpx">
						<button v-if="!isManager" class="cu-btn radius sm bg-orange margin-left-sm" @tap="goDetail(_item.goods.id)">
							<text class="cuIcon-edit"></text>详情
						</button>
						<radio @tap="check" v-else class="red" :class="checked?'checked':''" :checked="checked?true:false"></radio>
					</view>
				</view>
			</view>
			<!-- 头像部分 end -->
			
		</view>
	</view>
	<!-- 列表部分 end -->
</template>

<script>
	import * as confirm from '@/common/confirm.js'
	import {getDateDiff} from "@/utils/date/date.js"
	
	export default {
		data() {
			return {
				_item:{},
				checked:false
			};
		},
		name: 'favorite-item',
		props: {
			item: {
				type: Object,
				default: {}
			},
			index:{
				type:Number,
				default:0
			},
			isManager:{
				type:Boolean,
				default:false
			},
			iid:{
				type:Number,
				default:-1
			}
		},
		//页面创建方法,相当于onload
		created() {
			this._item=this.item
			this.id=this.iid
		},	
		methods: {
			getDateDiff(date){
				return getDateDiff(date)
			},
			goDetail(id){
				uni.navigateTo({
					url:"/pages/goods/detail?id="+id
				})
			},
			check(){
				this.checked=!this.checked
				this.$emit('check',this.index,this.checked)
			},
		}
	};
</script>

<style>
</style>